<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

	<ui:composition template="/faces/manager/xhtml/templates/template.xhtml">
		<ui:define name="manager-content">
			<table id="manager-content-panel" cellpadding="0" cellspacing="1">
				<tr>
					<td id="manager-content-header">
						<h:form>				
							<p:breadCrumb style="width:810px;">
								<p:menuitem value="#{msg['manager.menu.navigator.home']}"/>
								<p:menuitem ajax="false" value="#{msg['manager.menu.navigator.admin']}" action="/faces/manager/xhtml/main.xhtml" />
								<p:menuitem value="#{msg['manager.menu.navigator.cliente']}" />
							</p:breadCrumb>	
						</h:form>
					</td>
				</tr>
				<tr>
					<td id="manager-content-body">
						<h:form id="formCliente">	
							<p:growl id="showMessages" showDetail="true" />
							<p:fieldset legend="#{msg['manager.menu.left.admin.cliente.title']}" styleClass="manager-fieldset-content">
								<table id="panel-buttons" cellpadding="0" cellspacing="0">
									<tr>
										<td>
											<p:commandButton value="#{msg['manager.cliente.button.create']}" 
												action="#{clienteController.create}" ajax="false" icon="add-button"/>
											<p:spacer width="10px"/>
											<p:commandButton value="#{msg['manager.cliente.button.update']}" id="button-alterar"
												action="#{clienteController.edit}" ajax="false" icon="edit-button" disabled="#{!clienteController.selectedCliente}"/>
											<p:spacer width="10px"/>
											<p:commandButton value="#{msg['manager.cliente.button.visaoDetalhada']}" id="button-detalhes" 
												actionListener="#{clienteController.clienteDetalhado}"  ajax="true" icon="search-button" 
												update=":formCliente:display :formCliente:showMessages" oncomplete="clienteDialog.show()" disabled="#{!clienteController.selectedCliente}" />
										</td>
									</tr>
								</table>
								<p:spacer height="10px"/>
							 	<p:dataTable 
							 		id="dataTable"
									var="cliente" 
									value="#{clienteController.lazyModelCliente}" 
									rows="#{clienteController.pageSize}" 
									paginator="true"									
																
									selection="#{clienteController.cliente}"
									emptyMessage="#{msg['messages.list.not.found']}">
									
									<p:ajax event="rowSelect" update=":formCliente:button-detalhes :formCliente:button-alterar" listener="#{clienteController.onSelectedRow}"/>
									<p:ajax event="page" update=":formCliente:button-detalhes :formCliente:button-alterar" listener="#{clienteController.onPaged}"/>  
									<p:column selectionMode="single"  style="width:18px" />
									 
									<p:column headerText="#{msg['manager.cliente.list.grid.column.nome']}" >
										<h:outputText value="#{cliente.pessoa.nome}" />
									</p:column>
								
									<p:column headerText="#{msg['manager.cliente.list.grid.column.municipio']}" >
										<h:outputText value="#{cliente.endereco.municipio.nome}" />
									</p:column>
									
									<p:column headerText="#{msg['manager.cliente.list.grid.column.estado']}" >
										<h:outputText value="#{cliente.endereco.municipio.estado.sigla}" />
									</p:column>
									
									<p:column headerText="#{msg['manager.cliente.list.grid.column.status']}">
										<h:outputText value="#{msg['manager.cliente.list.label.ativo']}" rendered="#{cliente.ativo}"  />
										<h:outputText value="#{msg['manager.cliente.list.label.inativo']}" rendered="#{!cliente.ativo}"  />
									</p:column>
									
									<p:column styleClass="view-column-image">
										<p:outputPanel rendered="#{cliente.paginaPessoal}">
											<h:commandLink action="#{templateController.loadTemplate}" target="_blank" title="#{msg['manager.cliente.list.grid.column.site']}">
												<h:graphicImage value="#{resource['images:icons/16x16/site.png']}" /> 
												<f:param name="idCliente" value="#{cliente.id}" /> 
							            	</h:commandLink>
										</p:outputPanel>										
									</p:column>
									
								</p:dataTable>
								<p:spacer height="10px"/>								
							</p:fieldset>
							
							<p:dialog header="#{msg['manager.cliente.detalhado.title']}" widgetVar="clienteDialog" resizable="false"  
				              width="540" showEffect="clip" hideEffect="fold" modal="true">  
				  				
				  				<p:outputPanel id="display">
					        	 	<p:panel>
					        	 		<table cellpadding="0" cellspacing="0">
					        	 			<tr>
					        	 				<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.tipoPessoa.label']}:" /></td>
					        	 				<td class="view-column-value"> 
					        	 					<p:outputPanel rendered="#{clienteController.cliente.tipoPessoa == 'F'}">
							        	 				<h:outputText value="#{msg['manager.cliente.detalhado.tipoPessoa.fisica']}"  />
							        	 			</p:outputPanel>
							        	 			<p:outputPanel rendered="#{clienteController.cliente.tipoPessoa == 'J'}">
							        	 				<h:outputText value="#{msg['manager.cliente.detalhado.tipoPessoa.juridica']}"  />
							        	 			</p:outputPanel>
					        	 				</td>
					        	 			</tr>
					        	 			<tr>
					        	 				<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.nome.label']}:" /></td>
					        	 				<td class="view-column-value"><h:outputText value="#{clienteController.cliente.pessoa.nome}" /></td>
					        	 			</tr>
					        	 			<p:outputPanel rendered="#{clienteController.cliente.tipoPessoa == 'F'}">
					        	 				<tr>
						        	 				<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.pessoaFisica.cpf.label']}:" /></td>
						        	 				<td class="view-column-value"><h:outputText value="#{clienteController.pessoaFisica.cpf}"/></td>
					        	 				</tr>		              			              			
				              				</p:outputPanel>
				              				<p:outputPanel rendered="#{clienteController.cliente.tipoPessoa == 'F'}">
					        	 				<tr>
						        	 				<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.pessoaFisica.rg.label']}:" /></td>
						        	 				<td class="view-column-value"><h:outputText value="#{clienteController.pessoaFisica.rg}" /></td>
					        	 				</tr>		              			              			
				              				</p:outputPanel>
				              				<p:outputPanel rendered="#{clienteController.cliente.tipoPessoa == 'J'}">
					        	 				<tr>
						        	 				<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.pessoaJuridica.cnpj.label']}:" /></td>
						        	 				<td class="view-column-value"><h:outputText value="#{clienteController.pessoaJuridica.cnpj}"/></td>
					        	 				</tr>		              			              			
				              				</p:outputPanel>
				              				<p:outputPanel rendered="#{clienteController.cliente.tipoPessoa == 'J'}">
					        	 				<tr>
						        	 				<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.pessoaJuridica.cnpj.label']}:" /></td>
						        	 				<td class="view-column-value"><h:outputText value="#{clienteController.pessoaJuridica.cnpj}"/></td>
					        	 				</tr>		              			              			
				              				</p:outputPanel>
				              				<p:outputPanel rendered="#{clienteController.cliente.tipoPessoa == 'J'}">
					        	 				<tr>
						        	 				<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.pessoaJuridica.razaoSocial.label']}:" /></td>
						        	 				<td class="view-column-value"><h:outputText value="#{clienteController.pessoaJuridica.razaoSocial}" /></td>
					        	 				</tr>		              			              			
				              				</p:outputPanel>				              
					        	 		</table>	              			              				              			
				              		</p:panel>
				              		<p:spacer height="5px" />
				              		<p:panel>
				              			<table cellpadding="0" cellspacing="0">
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.contato.email.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.email}" /></td>
				              				</tr>
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.telefone.celular.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.telefoneCelular}" /></td>
				              				</tr>
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.telefone.fixo.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.telefoneFixo}" /></td>
				              				</tr>
				              			</table>				              		
				              		</p:panel>		              		
				              		<p:spacer height="5px" />
				              		<p:panel>
				              			<table cellpadding="0" cellspacing="0">
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.endereco.cep.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.endereco.cep}" /></td>				              					
				              				</tr>
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.endereco.rua.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.endereco.rua}" /></td>
				              				</tr>
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.endereco.numero.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.endereco.numero}" /></td>
				              				</tr>
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.endereco.complemento.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.endereco.complemento}" /></td>
				              				</tr>
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.endereco.bairro.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.endereco.bairro}" /></td>
				              				</tr>
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.endereco.municipio.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.endereco.municipio.nome}" /></td>
				              				</tr>
				              				<tr>
				              					<td class="view-column-label"><h:outputText value="#{msg['manager.cliente.detalhado.endereco.estado.label']}:" /></td>
				              					<td class="view-column-value"><h:outputText value="#{clienteController.cliente.endereco.municipio.estado.sigla}" /></td>
				              				</tr>
				              				
				              			</table>				          
				              		</p:panel>
				              		
			              		</p:outputPanel>		              		
			              		
		    				</p:dialog> 
						</h:form>
					</td>
				</tr>
			</table>
		</ui:define>
	
	</ui:composition>
</html>